package controllers

import (
	"ABlog/util"
	"fmt"
	"github.com/astaxie/beego"
)

type ApiAddToIndexArticleController struct {
	beego.Controller
}

func (c *ApiAddToIndexArticleController) Post() {
	title := c.GetString("title", "")
	id := c.GetString("id", "0")
	var filePath string = util.GetArticlePath("index")
	var code int = 200
	content := fmt.Sprintf("\r\n- [%s](/article/%s \"%s\")`%s`", title, id, title, util.GetDateString())
	err := util.Append(filePath, content)
	if nil != err {
		code = 500
	} else {
		code = 200
	}
	c.Data["json"] = fmt.Sprintf("{\"code\":%d, \"id\":\"%s\"}", code, id)
	c.ServeJSON()
}
